<?php
require_once 'test-00-inc.php';

start('Modification of elements (ii)');
/***/
test('By assignment it is possible to append
    something if it does NOT exist yet:','
    $html->body->div->b = "SOMETHING IN BOLD",
    $html->body->div->b["class"] = "TEST"
');

test('Inserting before the first child (by default):','
    $html->body->insert($html->body->ul)->source(),
    $html->body->insert($html->body->div->duplicate(), $html->body->h1)->source()
');

test('Replacing returns a replacement while removing -- a parent:','
    $html->body->h1->replace($html->body->div)->source(),
    $html->body->div->remove()->source()
');

test('It is possible to replace or remove a list:','
    $html->select("//b")->replace($html->create("<p><i>ITALIC</i></p>"))->source(),
    $html->body->p->all()->remove()->source()
');

test('A method can be applied to a list:','
    //  explicitely  //
    $html->select("//li")->apply("set_attribute", "class", "item")->source(),
    //  or implicitely  //
    $html->select("//li")->set_attribute("answer", "ok")->source(),
    $html->head->meta->all()->attribute("content")->items
');
/***/
test('A method can be applied to a source list,
    which in its turn can be applied to a target list:','
    $html->body
        ->append($html->create("<div>\\r\\n<ul id=\"NEW1\"/>\\r\\n<ul id=\"NEW2\"/>\\r\\n</div>"))
        //  target list of <ul/>
        ->items[0]->ul->all()
        //  source list of <li/>
        ->insert(new CxApply("//li", "duplicate"))
        //  returns all appended <li/>s
        ->source()
');
/***/

result($html);